package com.selftool.base;

import com.selftool.log.Logger;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * add by CYQ 2024年2月20日 抽象按钮，所有按钮逻辑实现均要继承此类，并在execute中编写按钮逻辑
 * */
public abstract class NCButton extends JButton {
    private NCFrame frame = null;

    public NCFrame getFrame (){
        return this.frame;
    }
    public NCFrame setFrame (NCFrame frame){
        return this.frame = frame;
    }

    public NCButton(){
        loadListener(null);
    }
    //    @Override
    public void loadListener(Object obj)
    {
        Logger.info("进入NCButton监听");
        ActionListener listener= new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Logger.info("进入actionPerformed监听...");
                try {
                    execute(obj);
                } catch (Exception ex) {
                    Logger.error("动作处理异常,"+ex.getMessage());
                } catch (Error e2) {
                    Logger.error("动作处理发生Error异常,"+e2.getMessage());
                }
            }
        };
        super.addActionListener(listener);
    }

    /** 按钮具体业务实现 */
    protected abstract void execute(Object obj) throws Exception;
}
